import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class StudentManager {
    public static ArrayList<Student> studentArrayList() {
        InputStreamReader isr = null;
        try {
            isr = new InputStreamReader(new FileInputStream("D:\\JAVA语言\\data\\students.txt"), "utf8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        BufferedReader br = new BufferedReader(isr);
        ArrayList<Student> ar = new ArrayList<Student>();
        String line;
        while (true) {
            try {
                if (!((line = br.readLine()) != null)) break;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            String student;
            String[] strArray1 = line.split("\t", 2);
            int index = line.indexOf("\t");
            Student s = new Student();
            s.setId(line.substring(0, index + 1));
            s.setName(line.substring(index + 1));
            ar.add(s);
        }
        try {
            br.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        System.out.println();
        return ar;
    }
    public  static ArrayList<Student> studentGrades() throws IOException{
        return Printshuzu.reader();
    }


    public static Integer Avager(Student s){
        return (Integer.valueOf(s.getChinese())+Integer.valueOf(s.getMath())+Integer.valueOf(s.getEnglish()))/3;
    }
    public static void printAll() throws IOException {
        ArrayList<Student> students=StudentManager.studentGrades();
        for (Student s : students) {
            Integer avager=Avager(s);
            System.out.println(String.format("学号:%s,姓名:%s, 数学成绩:%s, 语文成绩:%s, 英语成绩:%s, 平均分:%d, 总分:%d",
                    s.getId(),s.getName(),s.getMath(),s.getChinese(),s.getEnglish(),avager,avager*3));
        }
    }
    public static void getStudentById(String id) throws IOException {
        ArrayList<Student> students=StudentManager.studentGrades();
      // Scanner sc=new Scanner(System.in);
        //String getnumber=sc.next();
        for(Student s:students){
            if(s.getId().equals(id)){
                Integer avager=Avager(s);
                System.out.println(String.format("学号:%s,姓名:%s,数学成绩:%s,语文成绩:%s,英语成绩:%s,平均分:%d,总分:%d",
                        s.getId(), s.getName(),s.getMath(),s.getChinese(),s.getEnglish(),avager,avager*3));
            }
        }
    }
   //public static ArrayList<Student> students() throws IOException{
       // return
   public static void paixu() throws IOException{
       class studentclass{
           private List<Student> stulist;
           int size;
           public studentclass(){
               size=0;
               stulist=null;
           }
           public void creatcless(){
               Student student=new Student();
               stulist=new ArrayList<Student>();
               ArrayList<Student> students = StudentManager.studentArrayList();
               Student temp;
               int k;
               for(Student s:students){
                   temp=new Student(student.getId(),student.getName(),student.getMath(),student.getChinese(),student.getEnglish());
                   stulist.add(temp);
               }
               String output;{
                   StringBuilder studentinfo=new StringBuilder();
                   for(Student stu:stulist){
                       studentinfo.append(String.format("学号:%s,姓名:%s, 数学成绩:%s, 语文成绩:%s, 英语成绩:%s",
                               student.getId(),student.getName(),student.getMath(),student.getChinese(),student.getEnglish()));
                   }
               }


           }
       }
       printAll();
   }


}
